﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace DSVISUAL
{
    public class Netsh
    {
        public static void SetDns(params string[] dnss)
        {
            Process process = new Process();
            process.StartInfo = new ProcessStartInfo("netsh")
            {
                RedirectStandardInput = true,
                CreateNoWindow = true,
                RedirectStandardOutput = true,
                UseShellExecute = false,
                WindowStyle = ProcessWindowStyle.Hidden,
                Verb = "runas",
            };
            process.OutputDataReceived += Process_OutputDataReceived;
            process.Start();
            process.StandardInput.WriteLine("interface");
            process.StandardInput.WriteLine("ip");
            string output = string.Empty;
            for (int i = 0; i < dnss.Length; i++)
            {
                process.StandardInput.WriteLine("add dns 本地连接 " + dnss[i] + " index=" + i + " validate=false");
            }
            process.StandardInput.WriteLine("exit");
        }

        private static void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            MessageBox.Show(e.Data);
        }
    }
}
